package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.dto.sys.ProductSaveDto;
import com.atguigu.spzx.model.vo.product.ProductVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * title:
 * author: zgl
 * date: 2024/1/6
 * description：
 */
@RestController
@RequestMapping("/admin/product/product")
@Tag(name = "商品管理模块")
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("/{page}/{limit}")
    @Operation(summary = "查询商品列表接口")
    public Result list(@PathVariable Integer page,
                       @PathVariable Integer limit,
                       ProductDto productDto) {
        PageInfo<ProductVo> pageInfo = productService.getList(page, limit, productDto);
        return Result.ok(pageInfo);
    }

    @PostMapping("/save")
    @Operation(summary = "添加商品")
    public Result save(@RequestBody ProductSaveDto productSaveDto) {
        productService.save(productSaveDto);
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    @Operation(summary = "id查询商品接口")
    public Result getById(@PathVariable Long id) {
      ProductSaveDto productSaveDto= productService.getById(id);
        return Result.ok(productSaveDto);
    }

    @PutMapping("/updateById")
    @Operation(summary = "修改商品接口")
    public Result updateById(@RequestBody ProductSaveDto productSaveDto){
        productService.updateById(productSaveDto);
        return Result.ok();
    }

    @GetMapping("/updateAuditStatus/{id}/{auditStatus}")
    @Operation(summary = "修改审批状态接口")
    public Result updateAuditStatus(@PathVariable Long id, @PathVariable Integer auditStatus){
        productService.updateAuditStatus(id,auditStatus);
        return Result.ok();
    }

    @GetMapping("/updateStatus/{id}/{status}")
    @Operation(summary = "商品上下架接口")
    public Result updateStatus(@PathVariable Long id, @PathVariable Integer status){
        productService.updateStatus(id,status);
        return Result.ok();
    }
}
